<?php
/**
 * Created by PhpStorm.
 * User: Lin
 * Date: 2017/4/9 0009
 * Time: 下午 14:25
 */

/**
 * 递归重组节点数组为多维数组
 * @param $nodeArr
 * @param int $pid
 */
function node_merge($nodeArr,$access=null,$pid=0){
    $arr=array();
    foreach ($nodeArr as $v){
        if(is_array($access)){
            $v['access']=in_array($v['id'],$access)?1:0;
        }
        if($pid==$v['pid']){
            $v['child']=node_merge($nodeArr,$access,$v['id']);
            $arr[]=$v;
        }
    }
    return $arr;
}

/**递归重组角色数组 判断关联
 * @param $roleArr
 * @param $relationRole
 * @return array
 */
function role_judge($roleArr,$relationRole){
    $arr=array();
    foreach ($roleArr as $v){
        if (is_array($relationRole)){
            $v['relation']=in_array($v['id'],$relationRole)?1:0;
        }
        $arr[]=$v;
    }
    return $arr;
}

/**递归重组权限id数组为一维数组
 * @param $nodeList
 * @return array
 */
function composite_node_id($nodeList){
    $arr=array();
    foreach($nodeList as $v){
        if(is_array($v)){
            $arr= array_merge(composite_node_id($v),$arr);
        } else{
            $arr[]=$v;
        }
    }
    return $arr;
}